package cn.jiaqiang.chatgpt.data.infrastructure.dao;

import cn.jiaqiang.chatgpt.data.infrastructure.po.UserAccountPO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

/**
 * Created with IntelliJ IDEA.
 * Description: 用户账户 Dao
 * User: 86187
 * Date: 2024-04-02
 * Time: 16:22
 */
@Mapper
public interface IUserAccountDao extends BaseMapper<UserAccountPO> {

    /** 查询用户账户信息 */
    UserAccountPO queryUserAccount(@Param("openid") String openid);

    /** 查询用户账户信息 */
    @Select("SELECT openid, total_quota, surplus_quota, status, user_id " +
            "FROM user_account " +
            "WHERE user_id = #{userId}")
    UserAccountPO queryUserAccountWithUserId(@Param("userId") String userId);


    /** 插入新用户(第一次购买, 开户) */
    int insertUserAccount(UserAccountPO userAccountPOReq);

    /** 更新用户额度 */
    int addAccountQuota(UserAccountPO userAccountPOReq);

    /**  通过用户id查询用户*/
    UserAccountPO queryUserByUserId(@Param("userId") String userId);

    void updateUserOpenIdWithUserId(@Param("openId") String openId,@Param("userId") String userId);

    @Delete("delete from user_account where user_account.openid = #{openId}")
    void deleteDeprecatedUserAccount(@Param("userId") String openId);

    void subAccountQuota(String userId);
}
